package com.huike.clues.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.huike.clues.domain.vo.ReportVo;
import com.huike.clues.domain.vo.ReportsVo;
import com.huike.clues.dto.ReportDto;
import com.huike.clues.mapper.LreportMapper;
import com.huike.clues.service.LreportService;
import org.ehcache.core.util.CollectionUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;

/**
 * @author 木子李
 */
@Service
@Transactional
public class LreportServiceImpl implements LreportService {
    @Resource
    private LreportMapper lreportMapper;


    @Override
    public ReportVo selectCountByTime(Date beginTime, Date endTime) {
        int clue = lreportMapper.selectClueCount(beginTime,endTime);
        int beusiness = lreportMapper.selectBeusinessCount(beginTime,endTime);
        int customers = lreportMapper.selectCustomersCount(beginTime,endTime);
        List<Integer> prices = lreportMapper.selectPriveCount(beginTime,endTime);
        int prive = 0;
        if (CollUtil.isNotEmpty(prices)){
            prive=prices.stream().mapToInt(Integer::intValue).sum();
        }
        ArrayList<Integer> value = new ArrayList<>();
        value.add(clue);
        value.add(beusiness);
        value.add(customers);
        value.add(prive);
        List<String> list = List.of("线索数量", "商机数量", "客户数量", "销售金额");
        
        return ReportVo.builder()
                .text(list)
                .value(value)
                .build();
    }

    @Override
    public ReportVo selectCountBytoday() {
        int clue = lreportMapper.selectTodayClueCount();
        int beusiness = lreportMapper.selectTodayBeusinessCount();
        int customers = lreportMapper.selectTodayCustomersCount();
        List<Integer> prices = lreportMapper.selectTodayPriveCount();
        int prive = 0;
        if (CollUtil.isNotEmpty(prices)){
            prive=prices.stream().mapToInt(Integer::intValue).sum();
        }
        ArrayList<Integer> value = new ArrayList<>();
        value.add(clue);
        value.add(beusiness);
        value.add(customers);
        value.add(prive);
        List<String> list = List.of("线索数量", "商机数量", "客户数量", "销售金额");
        return ReportVo.builder()
                .text(list)
                .value(value)
                .build();
    }

    @Override
    public List<ReportsVo> selectCountByClueData(Date beginTime, Date endTime) {
        int clue = lreportMapper.selectTodayClueCount();
        int beusiness = lreportMapper.selectBeusinessCount(beginTime,endTime);
        int customers = lreportMapper.selectCustomersCount(beginTime,endTime);

        return List.of(
                new ReportsVo(clue, "新增线索"),
                new ReportsVo(beusiness, "新增商机"),
                new ReportsVo(customers, "新增客户")
        );
    }
}
